﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ElMexicanos.Base;
using ElMexicanos.Base.Models;
using ElMexicanos.Components.TowersTraps.Globals;


namespace ElMexicanos.Components.TowersTraps
{
    class Tower : Sprite
    {


    //// GLOBALS ////
        private int ATTACK = 10;
        private int DEFENSE = 20;
        private int PV = 20;

    //// ENUMS ////
        public enum TowerState
        {
            loadingState,
            waitingState,
            shootingState,
            ownedState
        }

    //// ATTRIBUTES ////
        private TowerState _state;
        private Vector2 _position;

        private int _attackpoints;
        private int _defensepoints;
        private int _pvpoints;
        private List<Mob> _locked_mob;

        //Reu 01/06/12
        private int _scopeRadius;
        private int _cost;
        private int _level;


        // Getter and Setter
        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public TowerState State
        {
            get { return _state; }
            set { _state = value; }
        }
        public int Attackpoints
        {
            get { return _attackpoints; }
            set { _attackpoints = value; }
        }
        public int Defensepoints
        {
            get { return _defensepoints; }
            set { _defensepoints = value; }
        }
        public int Pvpoints
        {
            get { return _pvpoints; }
            set { _pvpoints = value; }
        }
        internal List<Mob> Locked_mob
        {
            get { return _locked_mob; }
            set { _locked_mob = value; }
        }
    //// METHODS ////

        //Constructor
        public Tower(Vector2 position)
        {
            Position = position;
            Attackpoints = ATTACK;
            Defensepoints = DEFENSE;
            Pvpoints = PV;
            State = TowerState.waitingState;
        }


        public void SearchMob(List<Mob> all_mob)
        {

        }

        public void Shoot()
        {

        }

        public void SpecialShoot()
        {
    
        }

        public void MoveTo()
        {

        }
        
        public void UpdateLevel()
        {

        }

        public void Destroy()
        {
    
        }


    ////XNA METHODS ///

        //// SPRITES ////
        private AnimSprite loadingSprite;

        internal AnimSprite LoadingSprite
        {
            get { return loadingSprite; }
            set { loadingSprite = value; }
        }
        private AnimSprite waitingSprite;

        internal AnimSprite WaitingSprite
        {
            get { return waitingSprite; }
            set { waitingSprite = value; }
        }
        private AnimSprite shootingSprite;

        internal AnimSprite ShootingSprite
        {
            get { return shootingSprite; }
            set { shootingSprite = value; }
        }
        private AnimSprite ownedSprite;

        internal AnimSprite OwnedSprite
        {
            get { return ownedSprite; }
            set { ownedSprite = value; }
        }
        private AnimSprite upgradingSprite;

        internal AnimSprite UpgradingSprite
        {
            get { return upgradingSprite; }
            set { upgradingSprite = value; }
        }


        public void Initialize()
        {
            
        }

        public void LoadContent()
        {
            /*WaitingSprite = new AnimSprite(new AnimDefinition()
            {
                AssetName = "TowersTraps/Towers/tower",
                FrameRate = 8,
                FrameSize = new Point(118, 118),
                Loop = true,
                NbFrames = new Point(4, 2)
            }, new Vector2(this._position.X, this._position.Y));
            WaitingSprite.Initialize();*/

            if (State == TowerState.ownedState)
            {
                OwnedSprite.Initialize();
                OwnedSprite.LoadContent();
            }
            else if (State == TowerState.loadingState)
            {
                LoadingSprite.Initialize();
                LoadingSprite.LoadContent();
            }
            else if (State == TowerState.shootingState)
            {
                ShootingSprite.Initialize();
                shootingSprite.LoadContent();
            }
            else if (State == TowerState.waitingState)
            {
                WaitingSprite.Initialize();
                WaitingSprite.LoadContent();
            }
            //texture = RessourcesManager.GetInstance().GetTexture("");
        }

        public void Update(GameTime time)
        {
            if (_state ==  TowerState.ownedState)
            {
                OwnedSprite.Update(time);
            }
            else if (_state == TowerState.loadingState)
            {
                LoadingSprite.Update(time);
            }
            else if (_state == TowerState.shootingState)
            {
                ShootingSprite.Update(time);
            }
            else if (_state == TowerState.waitingState)
            {
                WaitingSprite.Update(time);  
            }
        }
        
        public void Draw(SpriteBatch spriteBatch, GameTime time)
        {
            if (_state == TowerState.ownedState)
            {
                OwnedSprite.Draw(spriteBatch, time);
            }
            else if (_state == TowerState.loadingState)
            {
                LoadingSprite.Draw(spriteBatch, time);
            }
            else if (_state == TowerState.shootingState)
            {
                ShootingSprite.Draw(spriteBatch, time);
            }
            else if (_state == TowerState.waitingState)
            {
                WaitingSprite.Draw(spriteBatch, time);
            }
        }
    }
}
